//
//  ZYXAFNSimpleViewController.m
//  Internet
//
//  AFNetworking 框架简单使用
//

#import "ZYXAFNSimpleViewController.h"

#import "AFNetworking.h"

@interface ZYXAFNSimpleViewController ()

@end

@implementation ZYXAFNSimpleViewController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self login];
    
    //[self video];
    
    //[self videoXML];
}


- (void)login
{
    // 1.获得请求管理者(管理请求, 帮助发请求)
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    // 声明服务器返回的数据是JSON
    //    mgr.responseSerializer = [AFJSONResponseSerializer serializer];
    
    // 2.封装请求参数
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"username"] = @"123";
    params[@"pwd"]      = @"123";
    
    // 3.发送GET请求
    [mgr GET:@"http://localhost:8080/MJServer/login" parameters:params
     success:^(AFHTTPRequestOperation *operation, id responseObject) { //  responseObject : 在这种情况下是字典
         ZYXLog(@"请求成功---%@", responseObject);
     }
     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         ZYXLog(@"请求失败---%@", error);
     }];
}

//2015-04-05 10:05:48.562 Internet[49578:1051181] 请求成功---{
//    success = "\U767b\U5f55\U6210\U529f";
//}




- (void)video
{
    // 1.获得请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    
    // 2.发送GET请求
    [mgr GET:@"http://localhost:8080/MJServer/video" parameters:nil
     success:^(AFHTTPRequestOperation *operation, NSDictionary *dict) { //  responseObject : 在这种情况下是字典
         ZYXLog(@"请求成功---%@", dict[@"videos"]);
     }
     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         ZYXLog(@"请求失败---%@", error);
     }];
    
}

/*
 2015-04-05 09:58:08.330 Internet[49146:1046780] 请求成功---(
 {
 id = 1;
 image = "resources/images/minion_01.png";
 length = 10;
 name = "\U5c0f\U9ec4\U4eba \U7b2c01\U90e8";
 url = "resources/videos/minion_01.mp4";
 },
 {
 id = 2;
 image = "resources/images/minion_02.png";
 length = 12;
 name = "\U5c0f\U9ec4\U4eba \U7b2c02\U90e8";
 url = "resources/videos/minion_02.mp4";
 },
 {
 id = 3;
 image = "resources/images/minion_03.png";
 length = 14;
 name = "\U5c0f\U9ec4\U4eba \U7b2c03\U90e8";
 url = "resources/videos/minion_03.mp4";
 },
 {
 id = 4;
 image = "resources/images/minion_04.png";
 length = 16;
 name = "\U5c0f\U9ec4\U4eba \U7b2c04\U90e8";
 url = "resources/videos/minion_04.mp4";
 },
 {
 id = 5;
 image = "resources/images/minion_05.png";
 length = 18;
 name = "\U5c0f\U9ec4\U4eba \U7b2c05\U90e8";
 url = "resources/videos/minion_05.mp4";
 },
 {
 id = 6;
 image = "resources/images/minion_06.png";
 length = 20;
 name = "\U5c0f\U9ec4\U4eba \U7b2c06\U90e8";
 url = "resources/videos/minion_06.mp4";
 },
 {
 id = 7;
 image = "resources/images/minion_07.png";
 length = 22;
 name = "\U5c0f\U9ec4\U4eba \U7b2c07\U90e8";
 url = "resources/videos/minion_07.mp4";
 },
 {
 id = 8;
 image = "resources/images/minion_08.png";
 length = 24;
 name = "\U5c0f\U9ec4\U4eba \U7b2c08\U90e8";
 url = "resources/videos/minion_08.mp4";
 },
 {
 id = 9;
 image = "resources/images/minion_09.png";
 length = 26;
 name = "\U5c0f\U9ec4\U4eba \U7b2c09\U90e8";
 url = "resources/videos/minion_09.mp4";
 },
 {
 id = 10;
 image = "resources/images/minion_10.png";
 length = 28;
 name = "\U5c0f\U9ec4\U4eba \U7b2c10\U90e8";
 url = "resources/videos/minion_10.mp4";
 },
 {
 id = 11;
 image = "resources/images/minion_11.png";
 length = 30;
 name = "\U5c0f\U9ec4\U4eba \U7b2c11\U90e8";
 url = "resources/videos/minion_11.mp4";
 },
 {
 id = 12;
 image = "resources/images/minion_12.png";
 length = 32;
 name = "\U5c0f\U9ec4\U4eba \U7b2c12\U90e8";
 url = "resources/videos/minion_12.mp4";
 },
 {
 id = 13;
 image = "resources/images/minion_13.png";
 length = 34;
 name = "\U5c0f\U9ec4\U4eba \U7b2c13\U90e8";
 url = "resources/videos/minion_13.mp4";
 },
 {
 id = 14;
 image = "resources/images/minion_14.png";
 length = 36;
 name = "\U5c0f\U9ec4\U4eba \U7b2c14\U90e8";
 url = "resources/videos/minion_14.mp4";
 },
 {
 id = 15;
 image = "resources/images/minion_15.png";
 length = 38;
 name = "\U5c0f\U9ec4\U4eba \U7b2c15\U90e8";
 url = "resources/videos/minion_15.mp4";
 },
 {
 id = 16;
 image = "resources/images/minion_16.png";
 length = 40;
 name = "\U5c0f\U9ec4\U4eba \U7b2c16\U90e8";
 url = "resources/videos/minion_16.mp4";
 }
 )
*/


- (void)videoXML
{
    // 1.获得请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    mgr.responseSerializer = [AFXMLParserResponseSerializer serializer];
    
    // 2.发送POST请求
    [mgr POST:@"http://localhost:8080/MJServer/video" parameters:@{@"type" : @"XML"}
      success:^(AFHTTPRequestOperation *operation, NSXMLParser *parser) {
          ZYXLog(@"请求成功---");
      }
      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          ZYXLog(@"请求失败---%@", error);
      }];
}

//2015-04-05 10:01:39.498 Internet[49373:1049258] 请求成功---



@end
